/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.RelationTypes;
import entity.TypeProduit;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author livetnediser
 */
@Stateless
public class RelationTypesFacade extends AbstractFacade<RelationTypes> {
    @PersistenceContext(unitName = "SexyShopPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public RelationTypesFacade() {
        super(RelationTypes.class);
    }
    
    public List<RelationTypes> findByTypeGen(int categorie) {
        List<RelationTypes> aux = em.createQuery("SELECT r FROM RelationTypes r WHERE r.idGen = :categorie")
        .setParameter("categorie", categorie)
        .getResultList();
	if(aux != null && aux.size()>0){
	    return aux;
	} else{
	    return null;
	}
    }
    

    public int findTypeBySubcategorie(int categorie){
        List<RelationTypes> result = em.createQuery("SELECT r FROM RelationTypes r WHERE r.idSpec = :categorie")
        .setParameter("categorie", categorie)
        .getResultList();
        
        return(result.get(0).getIdGen());
    }
    
    public List<RelationTypes> findByTypeSpec(int categorie){
        List<RelationTypes> result = em.createQuery("SELECT r FROM RelationTypes r WHERE r.idSpec = :categorie")
        .setParameter("categorie", categorie)
        .getResultList();
        
        return result;
    }
}
